package com.walterlife.dp.ProxyDP;

public class CommandExecuterProxy {
    private boolean isAdmin = false;
    private CommandExecuter commondExecuter;

    public CommandExecuterProxy(String user, String pwd) {
        if("admin".equals(user.toLowerCase()) 
                && "admin".equals(pwd)) {
            isAdmin = true; 
        } else {
            isAdmin = false;
        } 
        commondExecuter = new CommandExecuterImpl();
    } 

    public void runCommand(String cmd) throws Exception {
        if(isAdmin) {
            commondExecuter.runCommand(cmd);
        } else {
            if(cmd.trim().startsWith("rm")) {
                throw new Exception("CommandExecuterProxy runCommand: cmd " + cmd + " not permit for user except admin!!!");
            } else {
                commondExecuter.runCommand(cmd);
            } 
        } 
    } 
}
